package net.cardgame.orcalecard;

import java.util.List;

import android.app.Activity;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GalleryAdapter extends BaseAdapter {

	private Activity activity;
	private List<String> listPaths;
	public GalleryLoader imageLoader;
	int index = 0;
	private int width = 0;

	public GalleryAdapter(Activity a, List<String> list, boolean isSpecial) {
		activity = a;
		listPaths = list;
		imageLoader = new GalleryLoader(activity.getApplicationContext(),
				isSpecial);

		DisplayMetrics displaymetrics = new DisplayMetrics();
		activity.getWindowManager().getDefaultDisplay()
				.getMetrics(displaymetrics);
		width = displaymetrics.widthPixels;

	}

	public int getCount() {
		return listPaths.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	static class ViewHolder {
		TextView textView;
		ImageView imageview;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imageView = new ImageView(activity);
		imageLoader.DisplayImage(listPaths.get(position), imageView);

		if (width < 500)
			// Galaxy S2
			imageView.setLayoutParams(new GalleryFlow.LayoutParams(280, 440));

		else {
			// Galaxy Nexus
			imageView.setLayoutParams(new GalleryFlow.LayoutParams(350, 620));
		}
		return imageView;
	}
}
